<template>
  <div style="min-width:1366px;">
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>

            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" @clear="clearEvent" v-model="queryInfo.srm" clearable></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" @click="addNewSurgeryVisible = true" type="primary">新增手术信息</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="TableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="operationCode" label="手术编码" width="100"></el-table-column>
          <el-table-column label="更新" width="100">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                @click="showupdateSurgery(scope.row.id,scope.row.operationCode,scope.row.operationName)"
              >更新手术</el-button>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="60">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="open(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="searchCode" label="手术搜索码" width="150"></el-table-column>
          <el-table-column prop="operationName" label="手术名称"></el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>
    <el-dialog
      title="新增手术"
      :visible.sync="addNewSurgeryVisible"
      width="40%"
      :before-close="handleClose"
    >
      <el-card>
        <el-form label-position="right" label-width="80px" :model="addNewSurgeryList">
          <el-form-item label="手术编码">
            <el-input
              v-model="addNewSurgeryList.operationCode"
              style="width:45%"
              placeholder="请输入关键字"
            ></el-input>
          </el-form-item>
          <el-form-item label="手术名称">
            <el-input
              v-model="addNewSurgeryList.operationName"
              style="width:45%"
              placeholder="请输入关键字"
            ></el-input>
          </el-form-item>
        </el-form>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="addNewSurgery()">新增</el-button>
        <el-button size="mini" @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="更新手术"
      :visible.sync="updateSurgeryVisible"
      width="40%"
      :before-close="handleClose"
    >
      <el-card>
        <el-form label-position="right" label-width="80px" :model="updateSurgeryData">
          <el-form-item label="手术编码">
            <el-input
              v-model="updateSurgeryData.operationCode"
              style="width:45%"
              placeholder="请输入关键字"
            ></el-input>
          </el-form-item>
          <el-form-item label="手术名称">
            <el-input
              v-model="updateSurgeryData.operationName"
              style="width:45%"
              placeholder="请输入关键字"
            ></el-input>
          </el-form-item>
        </el-form>
      </el-card>

      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="open1()">更新</el-button>
        <el-button size="mini" @click="dialogVisible = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getOperationAllList,
  addOperationOne,
  updateSurgery,
  deleteSurgery
} from "@/api/rad";
export default {
  data() {
    return {
      queryInfo: {
        srm: "",
        pageList: 1,
        pageSize: 20
      },
      total: 0,
      TableData: [],
      addNewSurgeryVisible: false,
      addNewSurgeryList: {
        operationCode: "",
        operationName: ""
      },
      updateSurgeryData: {
        id: "",
        operationCode: "",
        operationName: ""
      },
      updateSurgeryVisible: false
    };
  },
  created: function() {
    this.getOperationAllList();
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      this.getOperationAllList();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.pageList = newPage;
      this.getOperationAllList();
    },
    clearEvent() {
      this.getOperationAllList();
    },
    getSearchList() {
      this.getOperationAllList();
    },
    async getOperationAllList() {
      let res = await this.$rad.getOperationAllList({
        srm: this.queryInfo.srm,
        pageList: this.queryInfo.pageList,
        pageSize: this.queryInfo.pageSize
      });
      console.log(res);
      this.TableData = res.rows;
      this.total = res.total;
    },
    async addNewSurgery() {
      let res = await this.$rad.addOperationOne({
        operationCode: this.addNewSurgeryList.operationCode,
        operationName: this.addNewSurgeryList.operationName
      });
      console.log(res);
      if (res.code == 1) {
        this.$message.success(res.msg);
        this.addNewSurgeryList.operationCode = "";
        this.addNewSurgeryList.operationName = "";
        this.addNewSurgeryVisible = false;
        this.getOperationAllList();
      } else {
        this.$message.error(res.msg);
      }
    },
    showupdateSurgery(id, operationCode, operationName) {
      this.updateSurgeryData.id = id;
      this.updateSurgeryData.operationCode = operationCode;
      this.updateSurgeryData.operationName = operationName;
      this.updateSurgeryVisible = true;
    },
    open1() {
      this.$confirm("此操作将更新本条规则, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.updateSurgery();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    async updateSurgery() {
      let res = await this.$rad.updateSurgery({
        id: this.updateSurgeryData.id,
        operationCode: this.updateSurgeryData.operationCode,
        operationName: this.updateSurgeryData.operationName
      });
      console.log(res);
      if (res.code == 1) {
        this.$message.success(res.msg);
        this.updateSurgeryVisible = false;
        this.getOperationAllList();
      } else {
        this.$message.error(res.msg);
      }
    },
    open(id) {
      this.$confirm("此操作将永久删除该规则, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.deleteSurgery(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    async deleteSurgery(id) {
      let res = await this.$rad.deleteSurgery({
        id: id
      });
      if (res.code == 1) {
        this.$message.success(res.msg);
        this.getOperationAllList();
      } else {
        this.$message.error(res.msg);
      }
    }
  }
};
</script>
<style>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
</style>